/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/12/02
*/
#include "LuaCheckBox.h"
#include "../../utilities/Log.h"

#ifdef EDUI_USE_LUAPLUS

EDUI_NAMESPACE_BEGIN

#define CObjPtr (CheckBox::ToCheckBox(m_cobj))

void* LuaCheckBox::GetInterface(void* data)
{
    if (!data) return 0;
    LuaCheckBox* checkBox = new LuaCheckBox((CheckBox*)data);
#ifdef EDUI_TEST_NEW_DELETE
    ++m_newdeleteNum;
    Log("[LuaCheckBox] new LuaCheckBox : %d, %d", checkBox, data);
#endif
    return checkBox;
}

void LuaCheckBox::Release()
{
#ifdef EDUI_TEST_NEW_DELETE
    --m_newdeleteNum;
    Log("[LuaCheckBox] delete LuaCheckBox : %d, %d, %s", this, m_cobj, this->GetName());
#endif
    delete this;
}

LuaCheckBox::LuaCheckBox(CheckBox* checkBox) : LuaButton(checkBox)
{}

LuaCheckBox::~LuaCheckBox()
{}

//----------------------------------------//

bool LuaCheckBox::IsSelected()
{
    return CObjPtr->IsSelected();
}

int LuaCheckBox::SetSelect(LuaState *L)
{
    LuaStack args(L);
    //cause RegisterObjectFunctor,the first param must be args[2]
    if (args[2].IsBoolean()){
        bool bEvent = true;
        bool bNotify = true;
        if (args[3].IsBoolean()) bEvent = args[3].GetBoolean();
        if (args[4].IsBoolean()) bNotify = args[4].GetBoolean();
        CObjPtr->SetSelect(args[2].GetBoolean(), bEvent, bNotify);
    }
    return 0;
}

void LuaCheckBox::SetGroup(const char* group)
{
    CObjPtr->SetGroup(group);
}

const char* LuaCheckBox::GetGroup()
{
    return CObjPtr->GetGroup();
}

bool LuaCheckBox::BindTableLayout(const char* name, int index)
{
    return CObjPtr->BindTableLayout(name, index);
}

const char* LuaCheckBox::GetBindTableLayoutName()
{
    return CObjPtr->GetBindTableLayoutName();
}

int LuaCheckBox::GetBindTableLayoutIndex()
{
    return CObjPtr->GetBindTableLayoutIndex();
}

//----------------------------------------//

void LuaCheckBox::Register(LuaState *L)
{
    LuaObject obj = LuaHelperNS::AddToMetas(L, "CheckBox", "Button");
    obj.SetObject("__index", obj);
    obj.RegisterDirect("__NewCObj__", &LuaCheckBox::GetInterface);

    obj.RegisterObjectDirect("IsSelected", (LuaCheckBox*)0, &LuaCheckBox::IsSelected);
    obj.RegisterObjectFunctor("SetSelect", &LuaCheckBox::SetSelect);
    obj.RegisterObjectDirect("SetGroup", (LuaCheckBox*)0, &LuaCheckBox::SetGroup);
    obj.RegisterObjectDirect("GetGroup", (LuaCheckBox*)0, &LuaCheckBox::GetGroup);
    obj.RegisterObjectDirect("BindTableLayout", (LuaCheckBox*)0, &LuaCheckBox::BindTableLayout);
    obj.RegisterObjectDirect("GetBindTableLayoutName", (LuaCheckBox*)0, &LuaCheckBox::GetBindTableLayoutName);
    obj.RegisterObjectDirect("GetBindTableLayoutIndex", (LuaCheckBox*)0, &LuaCheckBox::GetBindTableLayoutIndex);
}

#undef CObjPtr

EDUI_NAMESPACE_END

#endif